package com.DaMie.ssmschoolshop.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;


public class ImageUtil {

    public static String imagePath(MultipartFile file, String shopName) {
        if (file.isEmpty()) {
            return "false";
        }
        //图片保存路径
        String path = System.getProperty("user.dir")+"/src/main/webapp/image";
        //文件名
        String fileName=shopName+".jpg";
        File dest = new File(path + "/" +fileName);
        System.out.println("保存的绝对路径为:"+dest);
        if (!dest.getParentFile().exists()) { //判断文件父目录是否存在
            //创建目录
            dest.getParentFile().mkdir();
        }
        try {
            //图片上传
            file.transferTo(dest);
            return fileName;
        } catch (IllegalStateException e) {
            e.printStackTrace();
            return "false";
        } catch (IOException e) {
            e.printStackTrace();
            return "false";
        }


    }
}
